package com.hunit.mqtt_dome.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description : Jackson配置类
 * @Author : Sherlock
 * @Date : 2023/8/1 17:35
 */
@Configuration
public class JacksonConfig {

    /**
     * 配置ObjectMapper
     *
     * @return ObjectMapper实例
     */
    @Bean
    public ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        // 注册JavaTimeModule以支持Java 8日期/时间类型
        objectMapper.registerModule(new JavaTimeModule());
        // 禁用将日期表示为时间戳
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        // 格式化输出
        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
        return objectMapper;
    }
} 